<?php
/*=========================================*/
/* include_functions.php                   */
/* --------------------------------------- */
/* functions to be used throughout         */
/* the site, this should be included on    */
/* any page accessing the db or            */
/* dealing with sessions                   */
/*=========================================*/

require_once('include_db.php');
require_once('include_config.php');



/* message printing
 * ~~~~~~~~~~~~~~~~
 * $label is printed in the header of the page
 * $title is printed in the title bar of the content box
 * $body is printed in the body of the content box
 */
function message($ttf_label, $title, $body) {


				
			/*==============================================*/
			/*	This needs to be rewritten for mbj	*/
			/*==============================================*/



//    global $ttf;            // pull through the $ttf array for include_header.php (SMART!)
//    global $ttf_cfg;    // pull through the $ttf_cfg array (even smarter!)

    require_once "include_header.php";

    echo "<div class=\"contenttitle\">$title</div>\n";
    echo "<div class=\"contentbox\">\n";

        if (is_array($body)) {

            echo "<ul>\n";

            foreach ($body as $message) {

                echo "<li>$message</li>\n";

            };

            echo "</ul>\n";

        } else {

            echo "$body\n";

        };

    echo "</div>\n";

    require_once "include_footer.php";

};

/* mysql error printing
 * ~~~~~~~~~~~~~~~~~~~~
 * this function should be used with any call to a mysql function.
 * 
 * example use:
 *  if (!$result = mysql_query($sql)) showerror();
 *
 * remember that this function will exit the script if mysql
 * encounters an error. this is extremely necessary when issuing
 * a series of queries where a latter query depends on data from
 * a former query.
 */



			/*==============================================*/
			/*	This needs to be rewritten for mbj	*/
			/*==============================================*/

function showerror() {

    if (mysql_error()) {

        message("think tank forums", "fatal error", "mysql error ".mysql_errno().": ".mysql_error());

        die();
        
    } else {
        
        message("think tank forums", "fatal error", "could not connect to the mysql dbms.");

        die();

    };

};



/* input security cleaning
 * ~~~~~~~~~~~~~~~~~~~~~~~
 * this function should be used on every variable used in a script
 * coming from $_REQUEST, $_GET, and $_POST. it is extremely
 * important to use it on data used in mysql queries.
 */
function clean($input) {

    // do we want to trim?
    // $output = mysql_real_escape_string(trim($input));
    $output = mysql_real_escape_string($input);

    return($output);

};

// remove magic quotes (from php.net docs)
if (get_magic_quotes_gpc()) {
    function stripslashes_deep($value) {
        $value = is_array($value) ?
            array_map('stripslashes_deep', $value) :
            stripslashes($value);
        return $value;
    };
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
    $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
};


?>
